<?php

namespace App\Http\Service\api;

include_once("php-sms-sdk/SDK/SmsSDK.php");
class SMS
//容联云短信
{
    /**
     * @param $to
     * @param $datas
     * @param $tempId
     * @return string
     * 第三方容联运短信发送
     */
    public static function sendTemplateSMS($to, $datas, $tempId)
    {
        //主帐号
        $accountSid = config('Lottery.accountSid');
        //主帐号Token
        $accountToken = config('Lottery.accountToken');
        //应用Id
        $appId = config('Lottery.appId');
        //请求地址，格式如下，不需要写https://
        $serverIP = 'app.cloopen.com';
        //请求端口
        $serverPort = '8883';
        //REST版本号
        $softVersion = '2013-12-26';
        // 初始化REST SDK
        $rest = new \REST($serverIP, $serverPort, $softVersion);
        $rest->setAccount($accountSid, $accountToken);
        $rest->setAppId($appId);
        // 发送模板短信
        $result = $rest->sendTemplateSMS($to, $datas, $tempId);
        if ($result == NULL) {
            return "result error!";
        }
        if ($result->statusCode != 0) {
            return "error code :" . $result->statusCode . "<br>"."error msg :" . $result->statusMsg . "<br>";
        } else {
            // 获取返回信息
            $smsmessage = $result->TemplateSMS;
            return "Sendind TemplateSMS success!<br/>"."dateCreated:" . $smsmessage->dateCreated . "<br/>"."smsMessageSid:" . $smsmessage->smsMessageSid . "<br/>";
        }

    }
}
